package com.orm.analysis.util;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * Created with IntelliJ IDEA.
 * User: saman
 * Date: 10/17/13
 * Time: 10:39 AM
 * To change this template use File | Settings | File Templates.
 */
@Aspect
public class AppProfiler {
    Logger log = Logger.getLogger(AppProfiler.class);


    @Around("execution(* com.orm.analysis.dao.*.*(..))" )
       public Object profileDAO(ProceedingJoinPoint _pjp) throws Throwable {
           long start = System.currentTimeMillis();
           Object output = _pjp.proceed();
           long elapsedTime = System.currentTimeMillis() - start;
           log.debug("dao Method: " + _pjp.getSignature().toShortString() + ", execution time: " + elapsedTime + " ms.");
           System.out.println("dao Method: " + _pjp.getSignature().toShortString() + ", execution time: " + elapsedTime + " ms.");
           return output;
       }


//    @Around("execution(* com.orm.analysis.service.*.*(..))" )
    public Object profileService(ProceedingJoinPoint _pjp) throws Throwable {
        long start = System.currentTimeMillis();
        Object output = _pjp.proceed();
        long elapsedTime = System.currentTimeMillis() - start;
        log.debug("service Method: " + _pjp.getSignature().toShortString() + ", execution time: " + elapsedTime + " ms.");
        System.out.println("service Method: " + _pjp.getSignature().toShortString() + ", execution time: " + elapsedTime + " ms.");
        return output;
    }

}
